package easy;

import java.util.Arrays;

public class Solution_976 {

    public int largestPerimeter(int[] nums) {
        Arrays.sort(nums);
        for (int i = nums.length - 3; i >= 0; i--) {
            if (nums[i] + nums[i + 1] > nums[i + 2]) {
                return nums[i] + nums[i + 1] + nums[i + 2];
            }
        }
        return 0;
    }

    public static void main(String[] args) {
        Solution_976 model = new Solution_976();
        System.out.println(model.largestPerimeter(new int[]{2, 1, 2}));
        System.out.println(model.largestPerimeter(new int[]{1, 2, 1}));
        System.out.println(model.largestPerimeter(new int[]{3, 2, 3, 4}));
        System.out.println(model.largestPerimeter(new int[]{3, 6, 2, 3}));
    }
}
